import { BlockedTeamColorMap } from "../interface";
import { BlockedInCombatModule } from "../module";

export class BlockedEndState extends BlockedInCombatModule.State {
    override onEnter(): void {
        this.showWinner();
        this.runner.runDelay(() => {
            this.engine.stopGame();
        }, 40);
    }

    showWinner() {
        const winner = this.context.winner;
        if (winner === undefined) {
            this.context.groupSet.title("无人胜利");
            return;
        }
        const color = BlockedTeamColorMap[winner.data.color];
        this.context.groupSet.title(`${color.color}${color.name}胜利!`);
        this.context.groupSet.sendMessage(
            `${color.color}${color.name}胜利!§r (${winner
                .getAll()
                .map((p) => p.name)
                .join(",")})`
        );
    }
}
